package net.lainiao.morethread.Chapter4.demo4;

import java.util.concurrent.Callable;

/**
 * Created by Administrator on 2017/3/3.
 */
public class TaskValidator implements Callable<String> {
    private String user;
    private String password;
    private UserValidator validator;
    public TaskValidator(String user,String password,UserValidator validator){
        this.user=user;
        this.password=password;
        this.validator=validator;
    }

    @Override
    public String call() throws Exception {
        if(!validator.validate(user,password)){
            System.out.println(validator.getName()+" : The User has not been found");
            throw new Exception("Error validating user");
        }
        System.out.println(validator.getName()+" : The User has been found");
        return validator.getName();
    }
}
